package com.znzz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.znzz.dao.UserDao;
import com.znzz.domain.User;
import com.znzz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl2 implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public boolean save(User user) {
        return userDao.insert(user) > 0;
    }

    @Override
    public boolean update(User user) {
        return userDao.updateById(user) > 0;
    }

    @Override
    public boolean delete(String id) {
        return userDao.deleteById(id) > 0;
    }

    @Override
    public User getById(String id) {
        return userDao.selectById(id);
    }

    @Override
    public List<User> getAll() {
        return userDao.selectList(null);
    }

    /**
     * 分页查询
     *
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public IPage<User> getByPage(int currentPage, int pageSize) {
        IPage<User> page = new Page<>(currentPage, pageSize);
        return userDao.selectPage(page, null);
    }
}
